<?php include("../includes/header-member.php") ?>
<title>LazySwim</title>
</head>

<body>
<div id="page">
    <div id="page-top">
        <div id="page-bottom">
          <div id="header">
                <div id="header-info">
                    <h1>LAZYSWIM</h1>
                    <div class="description">Simplistic Swim System</div>
                </div>
				<!-- Header Goes Here -->
                <?php printHeader(); ?>
				<!-- Header Ends Here -->
                <div id="header-date">Today is <?php echo date('l, F jS, Y'); ?></div>
                <div id="header-cats">
				<!-- Welcome Message Starts Here -->
                    <ul>
					<?php include("../../includes/welcomeBar.php"); ?>
					</ul>
				<!-- Welcome Message Ends Here -->	
                </div>
            </div>
            <div id="main">

                <div id="sidebar">
                    <div class="sidebar-box">
                    <h3>Mail</h3>
                    <ul>
                        <li class="page_item"><a href="newMessage.php">New Message</a></li>
                        <li class="page_item"><a href="inbox.php">Inbox</a></li>
                        <li class="page_item"><a href="outbox.php">Outbox</a></li>
                    </ul>
                    </div>
                    <?php
					// include the corresponding navigation page
                    include("../../includes/navigation.php");
					?>     
                </div>

            <!-- main body -->

			<div class="featured-post"> 
			
				<div class="post-title"><h2>Inbox</h2></div>
				<div class="post-entry">
			
                <?php
                    require_once("../includes/dbInfo.php");
                    $user = $_SESSION['ls_userid'];
                
                    $messages_sql = mysql_query("SELECT * from messages where receiverID = '$user'  AND readStatus <> 'DELETED' ORDER BY timestamp DESC") 
                    or die(mysql_error()); 
                     
                     // menu items
                     
                    echo '<form name="updateMsgForm" method="post" action="updateMessage.php">';
                    echo '<input type="submit" name="delete" id="delete" value="Delete Messages">';
                    echo '<input type="submit" name="unread" id="unread" value="Mark Messages as Unread">';
                                       
                    echo "<br><table width=65% border=1 rules=rows cellpadding=10><tr>";
                    echo "<th></th><th>From</th><th>Date</th><th>Subject</th><th>Status</th></tr>";

                    while( $row = mysql_fetch_array($messages_sql)) {
                        // fetch the sender for each message
                        $sender_sql = mysql_query("SELECT name from accounts where userID = '$row[senderID]'") 
                        or die(mysql_error()); 
                        $sender = mysql_fetch_row($sender_sql);
                        
                        echo "<tr>";
                        echo "<td> <input type=\"checkbox\" name=\"messageIDs[]\" value=\"" . $row[messageID] . "\"> </td>";
                        echo "<td><center>" . $sender[0] . "</center></td>";
                        echo "<td><center>" . $row[timestamp] . "</center></td>";
                        echo "<td><center>";
                        if( $row[readStatus] == "UNREAD") {
                            echo "<b>(NEW) ";
                        }
                        echo "<a href=\"viewMessage.php?msgID=" . $row[messageID] . "\">" 
                            . $row[subject] . "</a></center></td>";
                         echo "<td><center>" . $row[readStatus] . "</center></td>";
                        echo "</tr>";
                    }
                    echo "</tr></table>";
                    echo "</form>";
                       
                ?>
				</div>
			</div>

            <div class="clear"></div>

            </div>
			<!-- Footer Goes Here -->
            <?php include("../../includes/footer.php"); ?>
			<!-- Footer Ends Here -->
        </div>
    </div>
</div>
</body>
</html>
